package com.spyz.hbase_api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

public class P1_HbaseConnection_1 {

    public static void main(String[] args) throws IOException {

        // 1. 创建连接配置对象
        Configuration conf = new Configuration();

        // 2. 添加连接配置
        conf.set("hbase.zookeeper.quorum","master,slave1,slave2");

        // 3. 创建连接
        //  默认使用同步连接
        Connection connection = ConnectionFactory.createConnection(conf);

        // 可以使用异步来连接（不推荐）
        CompletableFuture<AsyncConnection> asyncConnection = ConnectionFactory.createAsyncConnection(conf);

        // 4. 使用连接
        System.out.println(connection);

        // 5. 关闭连接
        connection.close();

    }
}
